<template>
  <div class="app-header-sticky" :class="{ show: y >= 78 }">
    <div class="container">
      <RouterLink class="logo" to="/" />
      <!-- 分类导航 -->
      <AppHeaderNav></AppHeaderNav>
      <div class="right">
        <RouterLink to="/">品牌</RouterLink>
        <RouterLink to="/">专题</RouterLink>
      </div>
    </div>
  </div>
</template>
<script setup name="AppHeaderSticky">
import AppHeaderNav from './app-header-nav.vue'
// 方式一： 传统方法来实现
// import { onMounted, ref } from 'vue'
// 定义数据来判断滚动条向下滚动了多少距离
/* const y = ref(0)
onMounted(() => {
  window.onscroll = () => {
    // 获取滚动条的滚动距离并赋值给y
    y.value = window.pageYOffset
  }
}) */
// 方式二： 使用@vueuse/core工具库来实现
import { useWindowScroll } from '@vueuse/core'
const { y } = useWindowScroll()

</script>
<style lang="less" scoped>
.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  // 默认不显示吸顶导航
  transform: translateY(-120%);
  opacity: 0;

  // 控制吸顶导航显示的类
  &.show {
    transition: all 0.3s linear;
    transform: none;
    opacity: 1;
  }

  .container {
    display: flex;
    align-items: center;
  }

  .logo {
    width: 200px;
    height: 80px;
    background: url(../assets/images/logo.png) no-repeat right 2px;
    background-size: 160px auto;
  }

  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid @xtxColor;

    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;

      &:hover {
        color: @xtxColor;
      }
    }
  }
}
</style>